package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.pojo.insert;
import com.itheima.service.UserService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private HttpServletRequest httpServletRequest;

    @GetMapping("/findByClassId")
    public ResponseResult getclass(){
        HttpSession session = httpServletRequest.getSession();
        User user = (User) session.getAttribute("user");
        if(user==null){
            return new ResponseResult(1,"请先登录",null);
        }
        ResponseResult responseResult = userService.SelectByClassId(user.getClassId());
        return responseResult;
    }
    @PostMapping("/addIntegral")
    public ResponseResult insert(@RequestBody insert insert){
        ResponseResult responseResult = userService.Insert(insert);
        return responseResult;
    }
//    @GetMapping("/findByClassId")
//    public ResponseResult getclass(){
//        HttpSession session = httpServletRequest.getSession();
//        User user = (User) session.getAttribute("user");
//
//        Set<ks_group> ks_groups = userService.SelectByClassId2(user);
//        for (ks_group ks:ks_groups) {
//            List<User> users = userService.SelectByClassId3(ks);
//            ks.setList(users);
//        }
//        for (ks_group kss:ks_groups) {
//            System.out.println(kss);
//        }
//
//        return new ResponseResult(0,"查询成功",ks_groups);
//    }
}
